package com.stdspringboot.ctrl;

import com.stdspringboot.entity.User;
import com.stdspringboot.util.Constant;
import com.stdspringboot.util.JWTUtil;
import com.stdspringboot.vo.JsonResult;
import com.stdspringboot.vo.UserInfo;
import com.stdspringboot.vo.UserInfoJWT;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RestController
public class GetUserInfoCtrl {

    @RequestMapping("/getUserInfo")
    public JsonResult get(String token){

        UserInfoJWT uij=null;
        try {
            uij= JWTUtil.parse(token,UserInfoJWT.class);
        } catch (IOException e) {
            e.printStackTrace();
        }

        JsonResult jr=new JsonResult(0,null);
        List roleList=new ArrayList();
        roleList.add("admin");

        UserInfo ui=new UserInfo();
        ui.setRoles(roleList);
        ui.setIntroduction("");
        ui.setName(uij.getName());
        ui.setAvatar("img/header.jpg");

        jr.setData(ui);
        return jr;
    }
}
